package com.sky.controller.User;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.Data;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userordercontroller")
@RequestMapping("/user/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;


    /**
     * 提交订单
     *
     * @return
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> sumbit(@RequestBody OrdersSubmitDTO dto) {
        OrderSubmitVO submitVO = orderService.sumbitShoppingCart(dto);
        return Result.success(submitVO);
    }

    /**
     * 分页查询历史订单详情
     *
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("从前端传递过来的查历史订单详情的数据为:{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.pageQuery(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据订单id查询订单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> getOrderDetailList(@PathVariable long id) {
        log.info("从前端传过来的查看订单详情的订单id为:{}", id);
        OrderVO orderVO = orderService.getOrderDetailList(id);
        return Result.success(orderVO);
    }

    /**
     * 根据订单id取消订单
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    public Result CancelOrder(@PathVariable Long id){
        log.info("前端传过来的取消订单的id为:{}",id);
        orderService.CancelOrder(id);
        return Result.success();
    }

    @PostMapping("repetition/{id}")
    public Result orderAgain(@PathVariable Long id){
        log.info("接收到前端传过来的再来一单的订单id为:{}",id);
        orderService.orderAgain(id);
        return Result.success();
    }

    /**
     * C端用户订单支付
     * @return
     */
    @PutMapping("payment")
    public Result<OrderPaymentVO> paymentOrder(@RequestBody OrdersPaymentDTO dto){
        log.info("收到用户端传来的用户支付的数据为:{}",dto);
        orderService.paymentOrder(dto);
        return Result.success();
    }

    /**
     * 用户催单
     * @param id
     * @return
     */
    @GetMapping("/reminder/{id}")
   public Result reminderOrder(@PathVariable Long id){
        orderService.reminderOrder(id);
        return Result.success();
   }
}
